﻿$(document).ready(function () {
    jQuery.fn.ForceNumberOnly =
    function () {
        return this.each(function () {
            $(this).live('keydown', function (e) {
                var key = e.charCode || e.keyCode || 0;
                // allow backspace, tab, delete, enter, arrows, numbers and keypad numbers ONLY
                // home, end, period, and numpad decimal
                if (e.shiftKey) return false;
                return (
                    key == 8 || // backspace
                    key == 9 || // tab
                    key == 13 || // enter
                    key == 46 || // delete
                //                key == 110 ||
                //                key == 190 ||
                    (key >= 35 && key <= 40) || // arrow keys/home/end
                    (key >= 48 && key <= 57) || // numbers on keyboard
                    (key >= 96 && key <= 105)); // number on keypad
            });
        });
    };
});


function validateEmail(email) {
    var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    if (filter.test(email)) {
        return true;
    }
    else {
        return false;
    }
}

function validatePassword(password) {
    var filter = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{6,10}$/;
    if (password.match(filter)) {
        return true;
    }
    else {
        return false;
    }
}

function IsMatchPassword(password, confirmPassword) {
    if (password === "")
        return false;
    if (password === confirmPassword) {
        return true;
    }
    else
        return false;
}
function checkStrength(password) {
    //initial strength
    var strength = 0;

    //if the password length is less than 6, return message.
    if (password.val().length < 6) {
        $(password).next().removeClass();
        $(password).next().addClass('short');
        return 'Too short';
    }

    //length is ok, lets continue.

    //if length is 8 characters or more, increase strength value
    if (password.val().length > 7) strength += 1;

    //if password contains both lower and uppercase characters, increase strength value
    if (password.val().match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) strength += 1;

    //if it has numbers and characters, increase strength value
    if (password.val().match(/([a-zA-Z])/) && password.val().match(/([0-9])/)) strength += 1;

    //if it has one special character, increase strength value
    if (password.val().match(/([!,%,&,@,#,$,^,*,?,_,~])/)) strength += 1;

    //if it has two special characters, increase strength value
    if (password.val().match(/(.*[!,%,&,@,#,$,^,*,?,_,~].*[!,%,&,@,#,$,^,*,?,_,~])/)) strength += 1;

    //now we have calculated strength value, we can return messages

    //if value is less than 2
    if (strength < 2) {
        $(password).next().removeClass();
        $(password).next().addClass('weak');
        return 'Weak'
    }
    else if (strength == 2) {
        $(password).next().removeClass();
        $(password).next().addClass('good');
        return 'Good'
    }
    else {
        $(password).next().removeClass();
        $(password).next().addClass('strong');
        return 'Strong'
    }
}
function setLocationToSession(location, locName) {
    $.ajax({
        type: "POST",
        url: "../Default.aspx/SetLocationToSession",
        data: JSON.stringify({ location: location, locName: locName }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        async: false,
        success: function (msg) {
            var obj = msg.d;
        },
        error: function (data, status, jqXHR) {
        }
    });
}
function CallJobLocation(location, locName) {
    setLocationToSession(location, locName);
    window.open('../Job/CategoryWiseJobSearch.aspx', '_blank');
    return false;
}
function setSearchStrToSession() {
    var what = $("#what").val();
    var where = $("#where").val();
    $.ajax({
        type: "POST",
        url: "../Default.aspx/SetSearchStrToSession",
        data: JSON.stringify({ what: what, where: where }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        async: false,
        success: function (msg) {
            var obj = msg.d;
        },
        error: function (data, status, jqXHR) {
        }
    });
}

function setQuickLinksToSession(quickLinkType) {
    $.ajax({
        type: "POST",
        url: "../Default.aspx/SetQuickLinksToSession",
        data: JSON.stringify({ quickLinkType: quickLinkType }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        async: false,
        success: function (msg) {
            var obj = msg.d;
        },
        error: function (data, status, jqXHR) {
        }
    });
}

function setAllJobsLinksToSession(categoryID) {
    $.ajax({
        type: "POST",
        url: "../Default.aspx/SetAllJobsLinksToSession",
        data: JSON.stringify({ categoryID: categoryID }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        async: false,
        success: function (msg) {
            var obj = msg.d;
        },
        error: function (data, status, jqXHR) {
        }
    });
}

function setGovtJobsLinksToSession(categoryID) {
    $.ajax({
        type: "POST",
        url: "../Default.aspx/setGovtJobsLinksToSession",
        data: JSON.stringify({ categoryID: categoryID }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        async: false,
        success: function (msg) {
            var obj = msg.d;
        },
        error: function (data, status, jqXHR) {
        }
    });
}

function setNewspaperJobsLinksToSession(categoryID) {
    $.ajax({
        type: "POST",
        url: "../Default.aspx/setNewspaperJobsLinksToSession",
        data: JSON.stringify({ categoryID: categoryID }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        async: false,
        success: function (msg) {
            var obj = msg.d;
        },
        error: function (data, status, jqXHR) {
        }
    });
}

function setJobTypeToSession(jobType) {
    $.ajax({
        type: "POST",
        url: "../Default.aspx/SetJobTypeToSession",
        data: JSON.stringify({ jobType: jobType }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        async: false,
        success: function (msg) {
            var obj = msg.d;
        },
        error: function (data, status, jqXHR) {
        }
    });
}
function CallCategoryWiseJobSearch() {
    setSearchStrToSession();
    window.open('../Job/CategoryWiseJobSearch.aspx', '_blank');
    return false;
}

function CallJobTypeLinks(typeId) {
    var quickLinkType = -1;

    if (typeId == '1') // Full Time
        quickLinkType = 1;
    else if (typeId == '2') //Internship
        quickLinkType = 2;
    else if (typeId == '3') //Part Time
        quickLinkType = 3;
    else if (typeId == '4') //Temporary
        quickLinkType = 4;
    else if (typeId == '5') //Contract
        quickLinkType = 5;

    setQuickLinksToSession(quickLinkType);
    window.open('../Job/CategoryWiseJobSearch.aspx', '_blank');
    return false;
}

function CallQuickLinks(quickLinkType) {
    setQuickLinksToSession(quickLinkType);
    window.open('../Job/CategoryWiseJobSearch.aspx', '_blank');
    return false;
}

function CallAllJobsLinks(categoryID) {
    setAllJobsLinksToSession(categoryID);
    window.open('../Job/CategoryWiseJobSearch.aspx', '_blank');
    return false;
}

function CallGovtJobsLinks(categoryID) {
    setGovtJobsLinksToSession(categoryID);
    window.open('../Job/CategoryWiseJobSearch.aspx', '_blank');
    return false;
}

function CallNewspaperJobsLinks(categoryID) {
    setNewspaperJobsLinksToSession(categoryID);
    window.open('../Job/CategoryWiseJobSearch.aspx', '_blank');
    return false;
}

function CallJobType(jobTypeID) {
    setJobTypeToSession(jobTypeID);
    window.open('../Job/CategoryWiseJobSearch.aspx', '_blank');
    return false;
}

function CallJobCategory(categoryID) {
    CallAllJobsLinks(categoryID);
    return false;
}

var millisecondsToWait = 12000;

function ClearSaveMsg() {
    //alert('ClearSaveMsg');
    $("#ctl00_MainContent_lblSaveMsg").fadeOut(12000);
    setTimeout(function () {
        $("#ctl00_MainContent_lblSaveMsg").empty();
        $("#ctl00_MainContent_lblSaveMsg").text("");
    }, millisecondsToWait);

}